import { Module } from '@nestjs/common'
import { UploadService } from './upload.service'
import { UploadController } from './upload.controller'
import { MulterModule } from '@nestjs/platform-express'
import { diskStorage } from 'multer'
import { extname } from 'path'

@Module({
   imports: [
      MulterModule.registerAsync({
         useFactory: () => ({
            storage: diskStorage({
               destination: 'uploads',
               filename(req, file, callback) {
                  const path = `${Date.now()}-${Math.random() * 1e10}${extname(file.originalname)}`
                  callback(null, path)
               }
            })
         })
      })
   ],
   providers: [UploadService],
   controllers: [UploadController]
})
export class UploadModule {}
